#!/bin/bash
# 工程造价政策文件助手环境安装脚本
# 适用于Linux/macOS系统

echo "=== 正在安装工程造价政策文件助手环境 ==="

# 1. 创建conda环境
echo "步骤1/5: 创建conda环境..."
conda create -n policyhelper python=3.10 -y
conda activate policyhelper || {
    echo "错误: 无法激活conda环境"
    exit 1
}

# 2. 安装Ollama
echo "步骤2/5: 安装Ollama..."
curl -fsSL https://ollama.com/install.sh | sh || {
    echo "错误: Ollama安装失败"
    exit 1
}

# 3. 下载模型
echo "步骤3/5: 下载AI模型..."
ollama pull qwen3:8b && ollama pull qwen2.5vl || {
    echo "错误: 模型下载失败"
    exit 1
}

# 4. 安装Python依赖
echo "步骤4/5: 安装Python依赖..."
pip install -U pip
pip install -r requirements.txt || {
    echo "错误: Python依赖安装失败"
    exit 1
}

# 5. 验证安装
echo "步骤5/5: 验证安装..."
echo "验证Ollama模型..."
ollama run qwen3:8b "测试" --verbose || echo "警告: Ollama模型验证失败"

echo "验证Python库..."
python -c "
import pychm, bs4, docx, llama_index, chromadb, streamlit, loguru
print('Python库验证通过')
" || echo "警告: Python库验证失败"

echo "=== 环境安装完成 ==="
echo "请运行以下命令激活环境:"
echo "conda activate policyhelper"